<?php 
	$status=array(
		0=>'<span class="label label-primary">Nuevo</span>',
		1=>'<span class="label label-success">Disponible</span>',
		2=>'<span class="label label-warning">Alerta</span>',
		3=>'<span class="label label-danger">Error</span>',
		);
?>

<input type="hidden" name='url' id='url' value="<?php echo $this->Html->url( '/', true ); ?>">
<div class="row">
 	<div class="col-md-12">
		<div class="page-header">
		  <h1>Zonas</h1>
		</div>
		<div class="row">
			<div class="col-md-6">
				<div class="btn-group pull-left">
					<?php echo $this->Html->link(__('Nuevo', true), array('controller' => 'zones', 'action' => 'add' ),array('class'=>'btn btn-default')); ?> 				  
			    <a href="#" class="btn btn-default" id='edit_bt'>Editar</a>
			    <button id='delete_bt'class="btn btn-default">Eliminar</button>
			    
				</div>
			</div>


			<div class="col-md-6 ">	
				<form method='post' >
					<div class="input-group">
		      	<input type="text" name='keyword'  class="form-control" placeholder="DNI">
		      	<span class="input-group-btn">
		        	<button class="btn btn-default" type="submit">Buscar</button>
		      	</span>
				  </div>
				</form>				
			</div>


		</div>

		


		<br>
		<br>
		<table class="table table-hover table-striped table-bordered">
				<thead>
					<tr>
						<th>#</th>
						<!--<th> <?php echo $this->Paginator->sort('id', 'Codigo'); ?></th>-->
						<th><?php echo $this->Paginator->sort('name', 'Nombre'); ?></th>
						<th><?php echo $this->Paginator->sort('status', 'Estado'); ?></th>
						<!-- <th>Action</th> -->
					</tr>
				</thead>
				<tbody>
					<?php foreach ($data as $item) :?>
						<tr>
							<td><input type="checkbox" name='item_ids[]' value="<?php echo $item['Zone']['id']?>"></td>
							<!-- <td><?php echo $item['Zone']['id']?></td> -->
							<td><a class='clients' href="#" data-id="<?php echo $item['Zone']['id']?>"><?php echo $item['Zone']['name']?></a></td>		
							<td><?php echo $status[$item['Zone']['status']]?></td>					
						</tr>
					<?php endforeach;?>	
				</tbody>
			</table>

			  <ul class="pagination">

	        <?php 
        		echo $this->Paginator->first('< first');
            echo $this->Paginator->prev( '<<', array( 'class' => '', 'tag' => 'li' ), null, array( 'class' => 'disabled', 'tag' => 'li' ) );
            echo $this->Paginator->numbers( array( 'tag' => 'li', 'separator' => '', 'currentClass' => 'active', 'currentTag' => 'a' ) );
            echo $this->Paginator->next( '>>', array( 'class' => '', 'tag' => 'li' ), null, array( 'class' => 'disabled', 'tag' => 'li' ) );
	        ?>
		    </ul>
 	</div>
</div>



<script type="text/javascript">
	function get_check_id(){
	    var result=0;
	    $('input[name=item_ids\\[\\]]').each(function() {
	        if( $(this).is(":checked")){
	            var user_id = $(this).val();	           
	            result =  user_id;
	        }
	    });
	    return result;
	}


	$(function(){
		
		var url=$("#url").val();
	/*	$("#edit_bt").click(function(){
			chck_id= get_check_id();
			redirect_url=url+"clients/edit/"+chck_id
			console.debug("THES: %o",redirect_url);
			//window.location.replace(redirect_url);
			return false;
		});*/

		$("#edit_bt").click(function(){
			chck_id= get_check_id();
			redirect_url=url+"zones/edit/"+chck_id
			window.location.replace(redirect_url);
			//console.debug("THES: %o",redirect_url);
			return false;
		});

		$("#delete_bt").click(function(){
			chck_id= get_check_id();			
			var selected = new Array();
			$("input:checkbox:checked").each(function() {
				selected.push($(this).val());
			});
			var client_json = $.post(url+"zones/delete",{ids:selected},function(result){
				location.reload();
				//return false;
		  	});			
			return false;
		});


});
</script>
